<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//Route::get('/', function () {
//    return view('welcome');
//});

Route::get('pay', 'PaymentController@payByAlipay');
Route::get('wxpay', 'PaymentController@payByWechat');

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
Route::redirect('/', '/products')->name('root');
Route::get('/products', 'ProductsController@index')->name('products.index');

Route::middleware('auth')->group(function (){
    Route::any('email_verify_notice', 'HomeController@emailVerifyNotice')->name('email_verify_notice');
    Route::any('email_verification/send', 'EmailVerificationController@send')->name('email_verification.send');
    Route::any('email_verification/verify', 'EmailVerificationController@verify')->name('email_verification.verify');
    Route::middleware('email_verified')->group(function (){                                //中间件注册名，ok（标准用法）
//    Route::middleware('\App\Http\Middleware\CheckIfEmailVerified')->group(function (){    //中间件全名，ok（第一个反斜杠可以省略）
//    Route::middleware('CheckIfEmailVerified')->group(function (){                         //中间件类名，error
        Route::get('/test', function (){
            return 'Ok';
        });
        Route::get('user_addresses', 'UserAddressesController@index')->name('user_addresses.index');
        Route::get('user_addresses/create', 'UserAddressesController@create')->name('user_addresses.create');
        Route::post('user_addresses', 'UserAddressesController@store')->name('user_addresses.store');
        Route::get('user_addresses/{address}', 'UserAddressesController@edit')->name('user_addresses.edit');
        Route::put('user_addresses/{address}', 'UserAddressesController@update')->name('user_addresses.update');
        Route::delete('user_addresses/{address}', 'UserAddressesController@destroy')->name('user_addresses.destroy');


        Route::post('/products/{product}/favorite', 'ProductsController@favor')->name('products.favor');
        Route::delete('/products/{product}/favorite', 'ProductsController@disfavor')->name('products.disfavor');
        Route::get('/products/favorites', 'ProductsController@favorites')->name('products.favorites');

        Route::post('/cart', 'CartController@add')->name('cart.add');
        Route::get('/cart', 'CartController@index')->name('cart.index');
        Route::delete('/cart/{sku}', 'CartController@remove')->name('cart.remove');

        Route::post('orders', 'OrdersController@store')->name('orders.store');
        Route::get('orders', 'OrdersController@index')->name('orders.index');
        Route::get('orders/{order}', 'OrdersController@show')->name('orders.show');

        Route::get('/payment/{order}/alipay', 'PaymentController@payByAlipay')->name('payment.alipay');
        Route::get('/payment/{order}/wechat', 'PaymentController@payByWechat')->name('payment.wechat');
        Route::get('/payment/alipay/return', 'PaymentController@alipayReturn')->name('payment.alipay.return');
    });
});
Route::post('/payment/alipay/notify', 'PaymentController@alipayNotify')->name('payment.alipay.notify'); //必须放在 auth 外，还得添加白名单
Route::post('/payment/wechat/notify', 'PaymentController@wechatNotify')->name('payment.wechat.notify'); //位置错误，稍后调整



Route::get('/products/{product}', 'ProductsController@show')->name('products.show');

Route::get('alipay', function() {
    return app('alipay')->web([
        'out_trade_no' => time(),
        'total_amount' => '0.1',
        'subject' => 'test subject - 测试',
    ]);
});